package com.yedou.consume;

import com.yedou.message.RegisterMessage;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(topic = "user-register-topic"
        , consumerGroup ="email-consumer-group")
@Slf4j
public class RegisterEmailConsumer implements RocketMQListener<RegisterMessage>{
    @Override
    public void onMessage(RegisterMessage message) {
        try {
            log.info("收到注册邮件发送任务：用户ID={}, 邮箱={}", message.getUserId(), message.getEmail());

            Thread.sleep(10000);
            // 模拟邮件发送过程（可能耗时较长的操作）
//            emailService.sendRegisterSuccessEmail(
//                    message.getEmail(),
//                    message.getUsername(),
//                    message.getRegisterTime()
//            );

            log.info("邮件发送成功：{}", message.getEmail());
        } catch (Exception e) {
            log.error("邮件发送失败：{}", e.getMessage(), e);
            // 可以根据业务需求添加重试机制
        }
    }
}
